extends layout

block headContent
	title Node Status
	
block content
	h1.h3 Node Status
	hr

	if (getblockchaininfo)
		if (false)
			p Data from RPC commands 
				a(href="/rpc-browser?method=getblockchaininfo") getblockchaininfo
				span , 
				a(href="/rpc-browser?method=getnetworkinfo") getnetworkinfo
				span , and 
				a(href="/rpc-browser?method=getnettotals") getnettotals

		if (false)
			pre
				code.json.bg-light #{JSON.stringify(getblockchaininfo, null, 4)}

		ul.nav.nav-tabs.mb-3
			li.nav-item
				a.nav-link.active(data-toggle="tab", href="#tab-details", role="tab") Details
			li.nav-item
				a.nav-link(data-toggle="tab", href="#tab-json", role="tab") JSON


		div.tab-content
			div.tab-pane.active(id="tab-details", role="tabpanel")
				div.card.shadow-sm.mb-3
					div.card-body.px-2.px-sm-3
						h3.h6.mb-0 Summary
						hr

						div.clearfix
							div.row
								div.summary-table-label Host : Port
								div.summary-table-content.text-monospace #{global.rpcClient.host + " : " + global.rpcClient.port}

							div.row
								div.summary-table-label Chain
								div.summary-table-content.text-monospace #{getblockchaininfo.chain}

							div.row
								div.summary-table-label Version
								div.summary-table-content.text-monospace #{getnetworkinfo.version} (#{getnetworkinfo.subversion})

							div.row
								div.summary-table-label Protocol Version
								div.summary-table-content.text-monospace #{getnetworkinfo.protocolversion}

							if (getblockchaininfo.size_on_disk)
								- var sizeData = utils.formatLargeNumber(getblockchaininfo.size_on_disk, 2);

								div.row
									div.summary-table-label Blockchain Size
									div.summary-table-content.text-monospace #{sizeData[0]} #{sizeData[1].abbreviation}B
										br
										span.text-muted  (pruned: #{getblockchaininfo.pruned})

							if (getblockchaininfo.softforks)
								div.row
									div.summary-table-label Soft Forks
									div.summary-table-content.text-monospace
										ul.list-unstyled
											each item, itemName in getblockchaininfo.softforks
												li
													div.d-inline-block.text-right(style="width: 75px;")
														span.font-weight-bold #{itemName}:
													
													span.mr-2.ml-2 type=#{item.type},

													if (item.active)
														span.mr-2
															span status=
															span.text-success active
															small.text-muted.ml-2 (height: #{item.height.toLocaleString()})

							div.row
								div.summary-table-label Block Count
								div.summary-table-content.text-monospace #{getblockchaininfo.blocks.toLocaleString()}
									br
									span.text-muted (headers: #{getblockchaininfo.headers.toLocaleString()})

							div.row
								div.summary-table-label Difficulty
								div.summary-table-content.text-monospace
									- var difficultyData = utils.formatLargeNumber(getblockchaininfo.difficulty, 3);
									span(title=parseFloat(getblockchaininfo.difficulty).toLocaleString(), data-toggle="tooltip")
										span #{difficultyData[0]}
										span  x 10
										sup #{difficultyData[1].exponent}

							div.row
								div.summary-table-label Status
								div.summary-table-content.text-monospace
									if (getblockchaininfo.initialblockdownload || getblockchaininfo.headers > getblockchaininfo.blocks)
										span Initial block download progress #{(100 * getblockchaininfo.verificationprogress).toLocaleString()}%
									else
										span.text-success Synchronized with network

							div.row
								div.summary-table-label Uptime
								div.summary-table-content.text-monospace
									- var startTimeAgo = moment.duration(uptimeSeconds * 1000);
									span #{startTimeAgo.format()}

							div.row
								div.summary-table-label Warnings
								div.summary-table-content.text-monospace
									if (getblockchaininfo.warnings && getblockchaininfo.warnings.trim().length > 0)
										span.text-danger #{getblockchaininfo.warnings}
									else
										span None

				div.card.shadow-sm.mb-3
					div.card-body.px-2.px-sm-3
						h3.h6.mb-0 Network Info
						hr

						div.clearfix
							div.row
								div.summary-table-label Peers
								div.summary-table-content.text-monospace #{getnetworkinfo.connections.toLocaleString()}

							div.row
								div.summary-table-label Network Traffic
								div.summary-table-content.text-monospace
									- var downData = utils.formatLargeNumber(getnettotals.totalbytesrecv, 2);
									- var downRateData = utils.formatLargeNumber(getnettotals.totalbytesrecv / uptimeSeconds, 2);
									- var upData = utils.formatLargeNumber(getnettotals.totalbytessent, 2);
									- var upRateData = utils.formatLargeNumber(getnettotals.totalbytessent / uptimeSeconds, 2);

									span Total Download: #{downData[0]} #{downData[1].abbreviation}B
									span.text-muted  (avg #{downRateData[0]} #{downRateData[1].abbreviation}B/s)
									br
									span Total Upload: #{upData[0]} #{upData[1].abbreviation}B
									span.text-muted  (avg #{upRateData[0]} #{upRateData[1].abbreviation}B/s)

							if (getnetworkinfo.networks)
								div.row
									div.summary-table-label Interfaces
									div.summary-table-content.text-monospace
										each item, index in getnetworkinfo.networks
											div
												span.font-weight-bold #{item.name}: 
												if (item.reachable)
													span.text-success reachable

												else
													span.text-danger unreachable

												if (item.proxy)
													span.text-muted.ml-3 (proxy: #{item.proxy})

							if (getnetworkinfo.localaddresses)
								div.row
									div.summary-table-label Local Addresses
									div.summary-table-content.text-monospace
										each item, index in getnetworkinfo.localaddresses
											div #{item.address}:#{item.port}
												span.text-muted.ml-3 (score: #{item.score.toLocaleString()})
							

			div.tab-pane(id="tab-json", role="tabpanel")

				ul.nav.nav-pills.mb-3
					li.nav-item
						a.nav-link.active(data-toggle="tab", href="#tab-getblockchaininfo", role="tab") getblockchaininfo
					li.nav-item
						a.nav-link(data-toggle="tab", href="#tab-getnettotals", role="tab") getnettotals
					li.nav-item
						a.nav-link(data-toggle="tab", href="#tab-getnetworkinfo", role="tab") getnetworkinfo
				
				div.tab-content
					div.tab-pane.active(id="tab-getblockchaininfo", role="tabpanel")
						div.card.shadow-sm.mb-3
							div.card-body
								h4.h6.mb-0 getblockchaininfo
								hr

								div.highlight
									pre
										code.json.bg-light(data-lang="json") #{JSON.stringify(getblockchaininfo, null, 4)}

					div.tab-pane(id="tab-getnettotals", role="tabpanel")
						div.card.shadow-sm.mb-3
							div.card-body
								h4.h6.mb-0 getnettotals
								hr

								div.highlight
									pre
										code.json.bg-light(data-lang="json") #{JSON.stringify(getnettotals, null, 4)}

					div.tab-pane(id="tab-getnetworkinfo", role="tabpanel")
						div.card.shadow-sm.mb-3
							div.card-body
								h4.h6.mb-0 getnetworkinfo
								hr

								div.highlight
									pre
										code.json.bg-light(data-lang="json") #{JSON.stringify(getnetworkinfo, null, 4)}
							
										